﻿
//生成[BlogPosts]Service代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FineAdmin.IService;
using FineAdmin.Model;
using FineAdmin.IRepository;
using FineAdmin.Common;

namespace FineAdmin.Service
{
    public class BlogPostsService : BaseService<BlogPostsModel>, IBlogPostsService
    {
        public IBlogPostsRepository BlogPostsRepository { get; set; }
        public IEnumerable<BlogPostsModel> GetBlogPostsList()
        {
            return BlogPostsRepository.GetBlogPostsList();
        }


        public dynamic GetListByFilter(BlogPostsModel filter, PageInfo pageInfo)
        {
            pageInfo.prefix = "a.";
            string _where = " BlogPosts a Left JOIN BlogPostsCategorie b ON a.CId = b.Id where 1=1 ";

            if (filter.CId.HasValue)
            {
                _where += string.Format(" and  {0}CId = {1}", pageInfo.prefix, filter.CId);
            }

            if (filter.PCId.HasValue)
            {
                _where += string.Format(" and  b.PId = {0}", filter.PCId);
            }

            _where = CreateTimeWhereStr(filter.StartEndDate, _where, pageInfo.prefix);

            pageInfo.returnFields = string.Format("{0}Id,{0}Title,{0}Excerpt,{0}Clicks,{0}Author,{0}State,b.Name as 'CName',{0}CreateTime,{0}UpdateTime", pageInfo.prefix);

            return GetPageUnite(filter, pageInfo, _where);
        }

       

        public IEnumerable<BlogPostsModel> GetListByFilter(BlogPostsModel filter, PageInfo pageInfo, out int total, string where = null)
        {
            pageInfo.prefix = "a.";
            string _where = " BlogPosts a Left JOIN BlogPostsCategorie b ON a.CId = b.Id where 1=1 ";

            if (filter.CId.HasValue)
            {
                _where += string.Format(" and  {0}CId = {1}", pageInfo.prefix, filter.CId);
            }

            if (filter.PCId.HasValue)
            {
                _where += string.Format(" and  b.PId = {0}", filter.PCId);
            }

            _where = CreateTimeWhereStr(filter.StartEndDate, _where, pageInfo.prefix);

            pageInfo.returnFields = string.Format("{0}Id,{0}Title,{0}Excerpt,{0}Clicks,{0}Author,{0}State,b.Name as 'CName',{0}CreateTime,{0}UpdateTime", pageInfo.prefix);

            return GetPageUnite(filter, pageInfo, out total, _where);
        }
    }

}